package de.tum.in.eist.poll.server;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;

import de.tum.in.eist.poll.client.AuthService;
import de.tum.in.eist.poll.shared.Lecturer;
import de.tum.in.eist.poll.shared.Student;
import de.tum.in.eist.poll.shared.exceptions.UserNotFoundException;

@SuppressWarnings("serial")
public class AuthServiceImpl extends RemoteServiceServlet implements AuthService{
	
	
	/**
	 * Validate the student login against the server
	 * 
	 * @param studentID
	 * 			login identifier
	 * 
	 * @param password
	 * 			TODO: user password 
	 * 
	 * @return
	 * 		the validated Student object with updated submittedPoll
	 * 			and availablePoll attributes
	 * 
	 */
	@Override
	public Student authenticateStudent(String studentID, String password) throws UserNotFoundException{
			Student student;
			try{
				student = (Student) Database.userDatabase.getUser(studentID);
			} catch (ClassCastException e){
				throw new UserNotFoundException();
			}
//			if (u.validatePassword(password)){
//				throw new IllegalArgumentException();
//			}
			student = Database.updateUser(student);
			return student;
	}
	
	/**
	 * Validate the lecturer login against the database
	 * 
	 * @param login
	 * 		the lecturer login identifier
	 * 
	 * @param password
	 * 		the lecturers password
	 * @return
	 *		the validated Lecturer object 
	 */
	
	public Lecturer authenticateLecturer(String login, String password) throws UserNotFoundException{
		Lecturer lecturer;
		try{
			lecturer = (Lecturer) Database.userDatabase.validate(login, password);
		} catch (ClassCastException e){
			throw new UserNotFoundException();
		}
		return lecturer;
	}
	
	

	

	
	
}
